package cn.edu.mju.dilidili.common.exception;

import cn.edu.mju.dilidili.common.utils.Result;
import cn.edu.mju.dilidili.common.utils.StateCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(value = RuntimeException.class)
    public Result<String> handle(RuntimeException e) {
        return new Result<>("", StateCode.RUNTIME_ERROR, e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public Result<String> handle(Exception e) {
        return new Result<>(StateCode.OTHER_ERROR);
    }

    @ExceptionHandler(value = VerifyException.class)
    public Result<String> handle(VerifyException e) {
        return new Result<>(StateCode.VERIFY_ERROR);
    }
}
